package com.baturu.ford.carvin.dal;

import com.baturu.offlineFord.dto.V2ImageInfoDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: chenjiahao
 * @Time: 2019/3/26
 */
public interface ImageInfoDAO {

    @Update({"drop table  if exists  ford_epc_self_image_info;",
            "CREATE TABLE `ford_epc_self_image_info` (\n" +
                    " id int(11) unsigned primary key auto_increment,",
                    "  `subGroup` varchar(12) NOT NULL DEFAULT '',\n" +
                    "  `imageName` text,\n" +
                    "  `pnc` varchar(64) NOT NULL DEFAULT '',\n" +
                    "  `imageCode` varchar(64) NOT NULL DEFAULT '',\n" +
                    "  `url` varchar(64) NOT NULL DEFAULT '',\n" +
                    "  `carTypeId` varchar(12) NOT NULL DEFAULT ''\n" +
                    ") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n" +
                    "\n"})
    void createImageInfo();

    @Select("select max(id) from ford_epc_parts_detail")
    Integer queryMaxId();

    @Select({"select DISTINCT t.subGroup,t4.ch imageName,t.pnc,t.imageCode,t2.imageName url,t.carTypeId  from ford_epc_parts_detail t\n" +
            "inner JOIN ford_epc_parts t2 on t2.imageIdx = t.imageidx \n" +
            "LEFT JOIN ford_epc_parts_subgroup t3 on t3.subGroup = t.subGroup  and t3.idx = t.carTypeId " +
            "INNER JOIN ford_epc_text t4 on t4.textIdx = t3.subGroupIdx",
            "inner JOIN ford_epc_car_type t5 on t.carTypeId = t5.idx",
            "WHERE t.id > ${start} AND t.id <=${end} and t4.ch is not null ",
            })
    List<V2ImageInfoDTO> queryImageInfo(@Param("start") Integer start,@Param("end") Integer end);

    @Select({"<script>INSERT INTO ford_epc_self_image_info (subGroup,imageName,pnc,imageCode,url,carTypeId) values",
            "<foreach item='item' collection= 'dtos' open='(' separator='),(' close=')'>",
            "#{item.subGroup},#{item.imageName},#{item.pnc},#{item.imageCode},#{item.url},#{item.carTypeId}",
            "</foreach></script>"})
    void insertV2ImageInfoDTO(@Param("dtos") List<V2ImageInfoDTO> strings);


}
